package ch.idsia.ai.agents.controllers.myai.tests;

import ch.idsia.ai.agents.controllers.myai.Element;
import ch.idsia.ai.agents.controllers.myai.Enemy;
import ch.idsia.ai.agents.controllers.myai.Obstacle;
import org.junit.*;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

/**
 * Created by IntelliJ IDEA.
 * User: Blake
 * Date: Jul 1, 2010
 * Time: 8:20:14 PM
 * To change this template use File | Settings | File Templates.
 */
public class ElementTest
{
    @Test   public void testElement()
    {
        Element test = new Element(1,0,2,1);
        assertNotNull("testElement", test);
    }
    
    @Test   public void testGetLocation()
    {
        int offset = 11;
        for(int i = 0; i < 1000; ++i)
        {
            int x1 = (int)(Math.random() *11);
            int y1 = (int)(Math.random() *11);

            Element test = new Element(x1+offset,y1+offset,x1+offset+1,y1+offset+1);
            int[] data = test.getLocation();

            assertTrue("testGetLocation: xValue.", data[0] == x1);
            assertTrue("testGetLocation: yValue.", data[1] == y1);
        }
    }

    @Test   public void  testGetDistance()
    {
        int offset = 11;
        for(int i = 0; i < 100; ++i)
        {
            int x = (int)(Math.random() * 11);
            Element test = new  Element(x+offset, 0, x+1, 1);
            assertTrue(test.getDistance() == x);
        }
    }

    @Test   public void testGetHeight()
    {
        int offset = 11;
        for(int i = 0; i < 100; ++i)
        {
            int y = (int)(Math.random() * 22);
            Element test = new  Element(0, y, y+1, 1);
            y = -1 * (y - 11);
            assertTrue(test.getHeight() == y);
        }
    }

    @Test   public void testGetName()
    {
        Element test = null;
        String[] values = {"ch.idsia.ai.agents.controllers.myai.Element", "ch.idsia.ai.agents.controllers.myai.Enemy", "ch.idsia.ai.agents.controllers.myai.Obstacle"};

        for (int i = 0; i < 1000; ++i);
        {
            int selector = (int) Math.floor(Math.random()*3);
            switch (selector)
            {
                case 0:
                    test = new Element(0,0,0,0);
                    break;
                case 1:
                    test = new Enemy(0,0,0,0,0);
                    break;
                case 2:
                    test = new Obstacle(0,0,0,0);
                    break;
            }

            assertTrue(test.getName().equals(values[selector]));
        }
    }

    @Test   public void testCompareTo()
    {
        Element test1 = null;
        Element test2 = null;

        for (int i = 0; i < 1000; ++i);
        {
            int distance1 = (int)Math.random()*100;
            int distance2 = (int)Math.random()*100;

            test1 = new Element(distance1, 0, 0, 0);
            test2 = new Element(distance2, 0, 0, 0);
            if(distance1 > distance2)
                assertTrue("testCompareTo", test1.compareTo(test2) == 1);
            else if (distance2 > distance1)
                assertTrue("testCompareTo", test1.compareTo(test2) == -1);
            else
                assertTrue("testCompareTo", test1.compareTo(test2) == 0);

        }
    }
}
